package com.xigua._数学;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/70:05
 */
public class _504_七进制数 {

    public static void main(String[] args) {
        System.out.println(convertToBase7(-7));
    }

    public static String convertToBase7(int num) {
        if (num == 0) return "0";
        StringBuilder ans = new StringBuilder("");
        boolean flag = true;
        if (num<0) {
            num = Math.abs(num);
            flag = false;
        }
        while (num>=7){
            int a = num%7;
            num = num/7;
            ans.insert(0,a);
        }
        ans.insert(0,num);
        return flag ? ans.toString() : ans.insert(0,"-").toString();
    }
}
